package org.chen.auth.controller;


import org.chen.auth.dto.LoginDTO;
import org.chen.auth.service.ILoginService;
import org.chen.auth.vo.LoginVO;
import org.chen.bas.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/login")
public class LoginController {
    @Autowired
    private ILoginService service;

    /**
     * 保存和修改公用的
     */
    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody LoginDTO loginDTO){
        try {
            /**
             * 登录成功以后返 token 和 user
             * 当 返回的结果 不是 domain
             * 我们会使用一个 VO View Object
             */
            LoginVO loginVO = service.login(loginDTO);
            return AjaxResult.success(loginVO);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("登录失败！"+e.getMessage());
        }
    }



}
